﻿using FinancePortal.Business.Infraestructure;
using FinancePortal.Business.Repository;
using FinancePortal.Domain.Model;
using System.Collections.Generic;
using System.Linq;
using NHibernate.Transform;
using NHibernate;

namespace FinancePortal.Business.Implementation
{
    public class AreaRepository : RepositoryBase<Area>, IAreaRepository
    {
        public AreaRepository(IUnitOfWork uow)
            : base(uow)
        { }

        public IList<int> GetChildIds(int areaId)
        {
            var area = GetById(areaId);
            var returnList = new List<int>();
            LoadList(area, returnList);

            return returnList;
        }

        private void LoadList(Area area, IList<int> areas)
        {
            //areas.Add(area.Id);
            //foreach (var item in area.ChildAreas)
            //    LoadList(item, areas);
        }

        public IQueryable<Area> GetByResource(int? areaId) //IList<int> areas)
        {
            return (from a in GetAll()
                where areaId == 1 || a.Id == areaId //ParentAreaId == areaId //areas.Contains(a.Id)
                select a);

        }
    }
}
